package kyssion.leetcode.num151_200;

import java.util.Stack;

public class code155_最小栈 {
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(1);
        minStack.push(2);
        minStack.push(3);
        System.out.println(minStack.getMin());
        System.out.println(minStack.top());
        minStack.push(-3);
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
    }

    static class MinStack {

        Stack<Integer> minStack;
        Stack<Integer> numStack;

        /**
         * initialize your data structure here.
         */
        public MinStack() {
            minStack = new Stack<>();
            numStack = new Stack<>();
        }

        public void push(int x) {
            numStack.push(x);
            int min = minStack.isEmpty()?Integer.MAX_VALUE:minStack.peek();
            minStack.push(Math.min(min, x));
        }

        public void pop() {
            numStack.pop();
            minStack.pop();
        }

        public int top() {
            return numStack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
    }
}